package com.winter.main.service.system.impl;

import com.github.pagehelper.PageHelper;
import com.winter.main.mapper.master.system.SysUserMapper;
import com.winter.main.mapper.read.system.ReadSysUserMapper;
import com.winter.main.model.entity.SysUser;
import com.winter.main.service.system.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Desc:
 * Author: dushuang
 * Date: Create in 2018/4/18
 */
@Service
public class SysUserServiceImpl implements SysUserService{

    @Autowired
    private SysUserMapper userMapper;

    @Autowired
    private ReadSysUserMapper reaUserMapper;

    @Override
    public SysUser selectOne(SysUser user) {
        return userMapper.selectOne(user);
    }

    @Override
    public SysUser findByUsername(String username) {
        return userMapper.findByUsername(username);
    }

    @Override
    @Transactional
    public void insertUser(SysUser user) {

        this.userMapper.insert(user);
    }

    @Override
    @Transactional
    public void insertReadUser(SysUser user) {
        // 测试事务
//        int a = 1/0;
        this.reaUserMapper.insert(user);
    }

    @Override
    public List<SysUser> findReadUser(Long id) {
        PageHelper.startPage(1,10);
        SysUser user = new SysUser();
        user.setId(id);
        return reaUserMapper.select(user);
    }
}
